UINotice = Class("")
local this = UINotice;


---@param obj GComponent
function UINotice:OnCreate(obj)
	self.gameObject = obj;

    ---@type FairyGUI.GTextField
    self.notice_desc = obj:GetChild("text")
    self.bg = obj:GetChild("bg")
    self.anim = obj:GetTransition("t0")
    self.gameObject.visible = false
    this.notice_desc = self.notice_desc
    ListenEvent(Config.EventType.Start_Marquee,self.onReceiveMsg,self);
    ListenEvent(Config.EventType.End_Marquee,self.EndMarqueeMsg,self)
    --utimer.timeCall(this.TestAdd,2000,5)
end
local times = 0
function UINotice.TestAdd()
    times = times + 1
    local message = "这是测试跑马灯哟 "
    for i = 1,times do
        message = message .." 这是测试 fuck"
    end
    message = message ..times
    logicMgr.ChatManager.AddMarquee(message)
end
function UINotice:OnDestroy()
    CloseEvent(Config.EventType.Start_Marquee,self.onReceiveMsg,self)
    CloseEvent(Config.EventType.End_Marquee,self.EndMarqueeMsg,self)
    self:EndMarqueeMsg()
    self.notice_desc = nil
    self.bg = nil
    self.anim = nil
    self.gameObject = nil
    self.tween = nil
    this.notice_desc = nil
end
function UINotice.GetTextSize(str)
    if this.notice_desc then
        this.notice_desc.text = str
        local w =  this.notice_desc.width + 30
        this.notice_desc.text = ""
        return w
    end
    return 1000000
end
function UINotice:OnEnable()

end
function UINotice:OnDisable()

end
function UINotice:onReceiveMsg(text,startPos,endPos,time)
    if Util.IsNull(self.gameObject) or Util.IsNull(self.notice_desc) then return end
    self.gameObject.visible = true
    self.notice_desc.text = text;
    self.notice_desc.x = startPos
    if self.tween then
        self.tween:Kill()
    end
    self.tween = self.notice_desc:TweenMoveX(endPos,time):SetEase(EaseType.Linear):OnComplete(function ()
        self:EndMarqueeMsg()
    end)

end
function UINotice:EndMarqueeMsg()
    if Util.IsNull(self.gameObject) then
        return
    end
    self.gameObject.visible = false
end

return UINotice;